﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web;
using DevExpress.Data;
using StockCrawlerLib.DAL;
using CrawlerController;

namespace StockCrawler.UserControl
{
    public partial class ucHistoryInfo : System.Web.UI.UserControl
    {
        //private StockRepository _stockRepo = new StockRepository();
        //private HistoryRepository _hisRepo = new HistoryRepository();

        public ucHistoryInfo()
        {
        }

        public ucHistoryInfo(IQueryable dt)
        {
            gridViewHistory.DataSource = dt;
            gridViewHistory.DataBind();
        }

        public void UpdateHistory(IQueryable dt)
        {
            gridViewHistory.DataSource = dt;
            gridViewHistory.DataBind();
        }

        protected void gridViewHistory_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e)
        {
            //try
            //{
            //    if (e.DataColumn.FieldName == "thay_doi")
            //    {
            //        float gia_dong_cua = (float)gridViewHistory.GetRowValues(e.VisibleIndex, new string[] { "gia_dong_cua" });
            //        float thay_doi = (float)gridViewHistory.GetRowValues(e.VisibleIndex, new string[] { "thay_doi" });
            //        float gia_tran = (float)gridViewHistory.GetRowValues(e.VisibleIndex, new string[] { "gia_tran" });
            //        float gia_san = (float)gridViewHistory.GetRowValues(e.VisibleIndex, new string[] { "gia_san" });
            //        if (thay_doi < 0)
            //        {
            //            if (gia_dong_cua == gia_san)
            //                e.Cell.ForeColor = System.Drawing.Color.FromArgb(0x66, 0xCC, 0xFF);
            //            else
            //                e.Cell.ForeColor = System.Drawing.Color.FromArgb(0xFF, 0x00, 0x00);
            //        }
            //        else if (thay_doi > 0)
            //            if (gia_dong_cua == gia_tran)
            //                e.Cell.ForeColor = System.Drawing.Color.FromArgb(0xFF, 0x00, 0xFF);
            //            else
            //                e.Cell.ForeColor = System.Drawing.Color.FromArgb(0x00, 0xFF, 0x00);
            //        else
            //        {
            //            e.Cell.ForeColor = System.Drawing.Color.FromArgb(0xF7, 0xFF, 0x31);
            //        }
            //    }
            //    else if (e.DataColumn.FieldName == "gia_dong_cua" || e.DataColumn.FieldName == "gia_mo_cua"
            //        || e.DataColumn.FieldName == "gia_cao_nhat" || e.DataColumn.FieldName == "gia_thap_nhat")
            //    {
            //        float gia_tham_chieu = (float)gridViewHistory.GetRowValues(e.VisibleIndex, new string[] { "gia_tham_chieu" });
            //        float gia_tran = (float)gridViewHistory.GetRowValues(e.VisibleIndex, new string[] { "gia_tran" });
            //        float gia_san = (float)gridViewHistory.GetRowValues(e.VisibleIndex, new string[] { "gia_san" });

            //        float value = (float)e.CellValue;
            //        if (value == gia_san)
            //            e.Cell.ForeColor = System.Drawing.Color.FromArgb(0x66, 0xCC, 0xFF);
            //        else if (value == gia_tran)
            //            e.Cell.ForeColor = System.Drawing.Color.FromArgb(0xFF, 0x00, 0xFF);
            //        else if (value < gia_tham_chieu)
            //            e.Cell.ForeColor = System.Drawing.Color.FromArgb(0xFF, 0x00, 0x00);
            //        else if (value > gia_tham_chieu)
            //            e.Cell.ForeColor = System.Drawing.Color.FromArgb(0x00, 0xFF, 0x00);
            //        else
            //            e.Cell.ForeColor = System.Drawing.Color.FromArgb(0xF7, 0xFF, 0x31);
            //    }
            //}
            //catch (Exception ex)
            //{
            //    throw ex;
            //}

        }
    }
}